package com.javabase.y2022.m04.day0429.v01;

/**
 * @descriptions: Solution
 * @author: Tom
 * @date: 2022/4/29 上午 09:16
 * @version: 1.0
 */
public class Solution {
    public static void main(String[] args) {
        int[] nums = new int[]{10,5,2,6};
        int k = 100;
        System.out.println(new Solution().numSubarrayProductLessThanK(nums, k));
    }

    public int numSubarrayProductLessThanK(int[] nums, int k) {

        int left = 0, N = nums.length;
        int multi = 1;
        int ans = 0;
        for (int right = 0;  right < N; right++) {
            multi *= nums[right];
            while(left <= right && multi >= k){
                multi /= nums[left];
                left++;
            }
            ans += right - left + 1;
        }
        return ans;
    }
}
